/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014年12月29日         luwei
 */

package com.coocaa.launcher.sidebar.left.item.speedup;

import android.content.Context;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.coocaa.launcher.sidebar.left.SideItemView;
import com.coocaa.x.framework.app.CoocaaApplication;
import com.coocaa.x.uipackage.SkinManager;
import com.tianci.appstore.R;
import com.tianci.appstore.ui.widget.CustomAnimationDrawable;
import com.tianci.appstore.utils.SkyConstants;

public class SpeedUpItem extends SideItemView {
    private int mDuring = 80;

    public SpeedUpItem(Context context) {
        super(context);
        //只有加速icon比其他大 特殊处理
        FrameLayout.LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
        iconParams.height = SkyConstants.Div(60);
        iconParams.width = SkyConstants.Div(60);
        mIcon.setLayoutParams(iconParams);
        mIcon.setBackgroundResource(getItemIconId());

    }

    public void beginSpeedUp() {

    }


    @Override
    public String getItemName() {
        // TODO Auto-generated method stub
        return SkinManager.getInstance().getString(R.string.main_speed);
    }

    @Override
    public int getItemIconId() {
        // TODO Auto-generated method stub
        return R.drawable.lanucher_speedup_anim1;
    }

    @Override
    public View getRightView() {
        if (mRightView == null) {
            TextView view = new TextView(mContext);
            view.setPadding(0, 0, CoocaaApplication.Div(15), 0);
            view.setTextAppearance(mContext, R.style.left_side_bar_memory_tip_style);
            view.setTextSize(SkyConstants.Dpi(39));
            view.setTextColor(SkinManager.getInstance().getColor(R.color.left_side_bar_memory_color));
            mRightView = view;
        }
        return mRightView;
    }

    public void endSpeedUp() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                mRightView.setVisibility(View.VISIBLE);
                ((TextView) mRightView).setText(getResources().getString(R.string.left_side_speeduped));
                TranslateAnimation anim = new TranslateAnimation(0, 0, -50, 0);
                anim.setDuration(200);
                mRightView.startAnimation(anim);
            }
        });

    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        mItemName.setText(getResources().getString(R.string.main_speed));
        mRightView.setVisibility(View.GONE);
        super.onFocusChange(v, hasFocus);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
    }

    private void startAnimation(CustomAnimationDrawable anim) {
        if (anim.isRunning())
            anim.stop();
        anim.setOneShot(true);
        anim.start();
    }

    public int getLeftMargin() {
        return SkyConstants.Div(41);
    }

    @Override
    public void destory() {
        // TODO Auto-generated method stub

    }
}
